package com.dream.inspect.modules.app.controller;

import java.util.*;

import com.dream.inspect.modules.sys.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.dream.inspect.common.exception.RRException;
import com.dream.inspect.common.utils.R;
import com.dream.inspect.common.utils.StringUtil;
import com.dream.inspect.modules.app.constants.AttrConstants;
import com.dream.inspect.modules.app.controller.common.CommonMethod;
import com.dream.inspect.modules.business.dao.SuperviseStandardDao;
import com.dream.inspect.modules.business.dao.SuperviseTempletConfDao;
import com.dream.inspect.modules.business.entity.SuperviseImageEntity;
import com.dream.inspect.modules.business.entity.SuperviseQuestionEntity;
import com.dream.inspect.modules.business.entity.SuperviseQuestionModifyEntity;
import com.dream.inspect.modules.business.entity.SuperviseRecordEntity;
import com.dream.inspect.modules.business.entity.SuperviseTempletEntity;
import com.dream.inspect.modules.business.service.SuperviseImageService;
import com.dream.inspect.modules.business.service.SuperviseProjectRecordService;
import com.dream.inspect.modules.business.service.SuperviseProjectService;
import com.dream.inspect.modules.business.service.SuperviseQuestionModifyService;
import com.dream.inspect.modules.business.service.SuperviseQuestionService;
import com.dream.inspect.modules.business.service.SuperviseRecordService;
import com.dream.inspect.modules.business.service.SuperviseStandardService;
import com.dream.inspect.modules.business.service.SuperviseTargetService;
import com.dream.inspect.modules.business.service.SuperviseTempletService;
import com.dream.inspect.modules.business.service.SysMessageService;
import com.dream.inspect.modules.dream.pojo.SysDeptFormMap;
import com.dream.inspect.modules.dream.pojo.SysUserFormMap;
import com.dream.inspect.modules.sys.dao.SysDeptDao;
import com.dream.inspect.modules.sys.entity.SysDeptEntity;
import com.dream.inspect.modules.sys.service.SysDeptService;
import com.dream.inspect.modules.sys.service.SysUserService;

/**
 * 实时拍录、分级督察、专项督察
 */


@Controller
@RequestMapping("/app/adds")
public class AppAddSuperviseController {

    @Autowired
    SuperviseStandardService superviseStandardService;
    @Autowired
    SuperviseProjectService superviseProjectService;
    @Autowired
    SuperviseTargetService superviseTargetService;
    @Autowired
    SuperviseProjectRecordService superviseProjectRecordService;
    @Autowired
    SuperviseRecordService superviseRecordService;
    @Autowired
    SuperviseTempletService superviseTempletService;
    @Autowired
    SuperviseQuestionService superviseQuestionService;
    @Autowired
    SuperviseQuestionModifyService superviseQuestionModifyService;
    @Autowired
    SuperviseImageService superviseImageService;
    @Autowired
    SysUserService sysUserService;
    @Autowired
    SysDeptDao sysDeptDao;

    @Autowired
    SuperviseTempletConfDao superviseTempletConfDao;
    @Autowired
    SuperviseStandardDao superviseStandardDao;
    @Autowired
    SysMessageService sysMessageService;
    @Autowired
    CommonMethod commonMethod;
    @Autowired
    SysDeptService sysDeptService;

    /**
     * 根据督查类别查询对应的督查小类
     * code = null level =1  查询督查类别
     * code = 督查类别sbdm level =2  查询小类
     * code = 督查小类sbdm level =3  查询子类
     * code = 督查子类sbdm level =4  查询检查项
     * code = null level = 4 name不为null 搜索检查项
     */
    @ResponseBody
    @RequestMapping(value = "getSuperviseList")
    public R getSuperviseList(String code, String level, String name) {
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        if(StringUtil.isNotEmpty(level)){
            list = superviseStandardService.getListByCode(code,level,name);
        } else {
            return R.error("级别不能为空");
        }
        return R.ok().put(AttrConstants.DATA,list);
    }   

    /**
     *app查询督查人员信息接口
     * @param deptId  部门Id
     * @param name  模糊搜索  支持 name  和 policeId
     *
     * @param currPage 当前页码
     * @param pageSize 每页大小
     * @return 分页搜索 一次返回10条数据
     */
    @ResponseBody
    @RequestMapping(value = "getSupervisePersons")
    public R getSupervisePersons(String deptId,  String name, Integer currPage, Integer pageSize) {
        List<SysUserFormMap> list = new ArrayList<SysUserFormMap>();
        String flag = "";
        if(currPage == null || pageSize == null || (currPage == 0 && pageSize == 0)){
            flag="1";
        }
        list = sysUserService.getUserLise(deptId,name,currPage,pageSize,flag);
        int count = sysUserService.getUserLise(deptId,name,0,0,flag).size();
        return R.ok().put(AttrConstants.DATA,list).put("count",count);
    }

    /**
     *app查询被督查人员信息接口
     * @param deptId  部门Id
     * @param name  模糊搜索  支持 name  和 policeId
     *
     * @param currPage 当前页码
     * @param pageSize 每页大小
     * @return 分页搜索 一次返回10条数据
     */
    @ResponseBody
    @RequestMapping(value = "getBeSupervisePersons")
    public R getBeSupervisePersons(String deptId,  String name, int currPage, int pageSize) {
        List<SysUserFormMap> list = new ArrayList<SysUserFormMap>();
        list = sysUserService.getUserLise(deptId,name,currPage,pageSize,"");
        int count = sysUserService.getUserLise(deptId,name,0,0,"").size();
        return R.ok().put(AttrConstants.DATA,list).put("count",count);
    }


    /**
     * 查询被督查部门接口
     * @param name
     * @param currPage
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getBeSuperviseDept")
    public R getBeSuperviseDept(String name,String deptId, String sfdctx, int currPage, int pageSize) {
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("name",name);
        map.put("deptId",deptId);
        map.put("currPage",(currPage-1)*pageSize);
        map.put("pageSize",pageSize);
        map.put("sfdctx",StringUtil.isEmpty(sfdctx) ? "1" : sfdctx);//是否督查条线(0：是，1：否)，被督查单位只能是非督查条线
        list = sysDeptDao.queryDeptList(map);
        return R.ok().put(AttrConstants.DATA,list).put("count",sysDeptDao.queryDeptListCount(map));
    }

    
    /**
     * 查询督察记录List
     * 
     * @param params (专项ID,整改状态,督察方式,时间排序
     * @return
     */
    @ResponseBody
    @RequestMapping("/findSuperviseRecordList")
    public R findSuperviseRecordList(@RequestParam Map<String, String> params){
        
        int countNum = 0;
        countNum = superviseRecordService.findSuperviseRecordListCount(params);
        List<SuperviseRecordEntity> srsList = new ArrayList<SuperviseRecordEntity>();
        if (countNum != 0) {
            srsList = superviseRecordService.findSuperviseRecordList(params);
        }
        
        return R.ok().put(AttrConstants.DATA, srsList).put(AttrConstants.COUNT_NUM, countNum);
    }
    
    /**
     * 查询督察记录详情
     * 
     * @param params 督察记录的ID
     * @return
     */
    @ResponseBody
    @RequestMapping("/findSuperviseRecordById")
    public R findSuperviseRecordById(@RequestParam Map<String, String> params){
        
        SuperviseRecordEntity srEntity = new SuperviseRecordEntity();
        srEntity = superviseRecordService.findSuperviseRecordById(params);
        return R.ok().put(AttrConstants.DATA, srEntity);
    }
    
    /**
     * 查询督察问题List(带统计，有照片)
     * 
     * @param params (督察记录ID)
     * @return
     */
    @ResponseBody
    @RequestMapping("/findSuperviseQuestionListCount")
    public R findSuperviseQuestionListCount(@RequestParam Map<String, String> params){
        
        int countNum = 0;
        countNum = superviseQuestionService.findSuperviseQuestionListForCountNum(params);
        List<SuperviseQuestionEntity> srsList = new ArrayList<SuperviseQuestionEntity>();
        if (countNum != 0) {
            srsList = superviseQuestionService.findSuperviseQuestionListForCount(params);
            
            if(srsList != null && srsList.size() > 0) {
                for (SuperviseQuestionEntity temp : srsList) {
                    String questionId = String.valueOf(temp.getId());
                    Map<String, String> imageMap = new HashMap<String, String>();
                    imageMap.put("questionId", questionId);
                    imageMap.put("picType", "1");
                    List<SuperviseImageEntity> siList = superviseImageService.findSuperviseImageList(imageMap);
                    if (siList != null && siList.size() > 0) {
                        temp.setImageList(siList);
                    }
                }
            }
        }
        
        return R.ok().put(AttrConstants.DATA, srsList).put(AttrConstants.COUNT_NUM, countNum);
    }
    
    /**
     * 查询督察问题List(有查询过滤，不带统计,无照片)
     * 
     * @param params (督察记录ID)
     * @return
     */
    @ResponseBody
    @RequestMapping("/findSuperviseQuestionList")
    public R findSuperviseQuestionList(@RequestParam Map<String, String> params){
        
        int countNum = 0;
        countNum = superviseQuestionService.findSuperviseQuestionListCount(params);
        List<SuperviseQuestionEntity> srsList = new ArrayList<SuperviseQuestionEntity>();
        if (countNum != 0) {
            srsList = superviseQuestionService.findSuperviseQuestionList(params);
        }
        
        return R.ok().put(AttrConstants.DATA, srsList).put(AttrConstants.COUNT_NUM, countNum);
    }
    
    /**
     * 查询督察问题详情
     * 
     * @param params (督察记录ID)
     * @return
     */
    @ResponseBody
    @RequestMapping("/findSuperviseQuestionDetail")
    public R findSuperviseQuestionDetailById(@RequestParam Map<String, String> params){
        SuperviseQuestionEntity resultEntity = new SuperviseQuestionEntity();
        List<SuperviseQuestionEntity> srsList = superviseQuestionService.findSuperviseQuestionDetailList(params);
        //获取照片list
        if (srsList != null && srsList.size() > 0) {
            resultEntity = srsList.get(0);
            String wtglId = String.valueOf(resultEntity.getQuestionId());
            Map<String, String> imageMap = new HashMap<String, String>();
            imageMap.put("questionId", wtglId);
            imageMap.put("picType", "1");
            List<SuperviseImageEntity> siList = superviseImageService.findSuperviseImageList(imageMap);
            if (siList != null && siList.size() > 0) {
                resultEntity.setImageList(siList);
            } else {
                resultEntity.setImageList(new ArrayList<SuperviseImageEntity>());
            }
        }

        return R.ok().put(AttrConstants.DATA, resultEntity);
    }
    
    /**
     * 查询督察整改历史记录List（根据督察记录ID，分页查询且带照片）
     * 
     * @param params (督察记录ID)
     * @return
     */
    @ResponseBody
    @RequestMapping("/findSuperviseQuestionModifyListByPage")
    public R findSuperviseQuestionModifyListByPage(@RequestParam Map<String, String> params){
        
        int countNum = 0;
        countNum = superviseQuestionModifyService.findSuperviseQuestionModifyListCount(params);
        List<SuperviseQuestionModifyEntity> srsList = new ArrayList<SuperviseQuestionModifyEntity>();
        if (countNum != 0) {
            srsList = superviseQuestionModifyService.findSuperviseQuestionModifyListByPage(params);
            if(srsList != null && srsList.size() > 0) {
                for (SuperviseQuestionModifyEntity temp : srsList) {
                    List<SuperviseImageEntity> siList = new ArrayList<SuperviseImageEntity>();
                    String sqmId = String.valueOf(temp.getId());
                    Map<String, String> imageMap = new HashMap<String, String>();
                    imageMap.put("questionId", sqmId);
                    imageMap.put("picType", "2");
                    siList = superviseImageService.findSuperviseImageList(imageMap);
                    temp.setImageList(siList);
                }
            }
        }
        
        return R.ok().put(AttrConstants.DATA, srsList).put(AttrConstants.COUNT_NUM, countNum);
    }
    
    /**
     * 查询督察整改记录List（根据问题详情查询整改历史，不分页查询且有照片）
     * 
     * @param params (督察问题ID)
     * @return
     */
    @ResponseBody
    @RequestMapping("/findSuperviseQuestionModifyList")
    public R findSuperviseQuestionModifyList(@RequestParam Map<String, String> params){
        
        List<SuperviseQuestionModifyEntity> srsList = new ArrayList<SuperviseQuestionModifyEntity>();
        srsList = superviseQuestionModifyService.findSuperviseQuestionModifyList(params);
        
        if(srsList != null && srsList.size() > 0) {
            for (SuperviseQuestionModifyEntity temp : srsList) {
                List<SuperviseImageEntity> siList = new ArrayList<SuperviseImageEntity>();
                String modifyId = String.valueOf(temp.getId());
                Map<String, String> imageMap = new HashMap<String, String>();
                imageMap.put("questionId", modifyId);
                imageMap.put("picType", "2");
                siList = superviseImageService.findSuperviseImageList(imageMap);
                temp.setImageList(siList);
            }
        }
        
        return R.ok().put(AttrConstants.DATA, srsList);
    }
    
    /**
     * 查询督察整改历史记录List（查询整改历史，带过滤功能，分页查询无照片）
     * 
     * @param params (督察问题ID)
     * @return
     */
    @ResponseBody
    @RequestMapping("/findSuperviseQuestionModifyHistory")
    public R findSuperviseQuestionModifyHistory(@RequestParam Map<String, String> params){
        int countNum = 0;
        countNum = superviseQuestionModifyService.findSuperviseQuestionModifyHisCount(params);
        List<SuperviseQuestionModifyEntity> srsList = new ArrayList<SuperviseQuestionModifyEntity>();
        if (countNum != 0) {
            srsList = superviseQuestionModifyService.findSuperviseQuestionModifyHisByPage(params);
        }
        
        return R.ok().put(AttrConstants.DATA, srsList).put(AttrConstants.COUNT_NUM, countNum);
    }
    
    /**
     * 查询督察整改历史记录详情（查询整改历史，带过滤功能，分页查询无照片）
     * 
     * @param params (督察问题ID)
     * @return
     */
    @ResponseBody
    @RequestMapping("/findSuperviseQuestionModifyHistoryDetail")
    public R findSuperviseQuestionModifyHistoryDetail(@RequestParam Map<String, String> params){
        
        List<SuperviseQuestionModifyEntity> srsList = new ArrayList<SuperviseQuestionModifyEntity>();
        srsList = superviseQuestionModifyService.findSuperviseQuestionModifyHisByPage(params);
        if(srsList != null && srsList.size() > 0) {
            for (SuperviseQuestionModifyEntity temp : srsList) {
                List<SuperviseImageEntity> siList = new ArrayList<SuperviseImageEntity>();
                String modifyId = String.valueOf(temp.getId());
                Map<String, String> imageMap = new HashMap<String, String>();
                imageMap.put("questionId", modifyId);//整改的反馈照片
                imageMap.put("picType", "2");
                siList = superviseImageService.findSuperviseImageList(imageMap);
                temp.setImageList(siList);
            }
        }
        
        return R.ok().put(AttrConstants.DATA, srsList);
    }
    
    /**
     * 审核查询整改历史记录（审核页面用查询整改历史）
     * 
     * @param params (问题整改ID)
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkFindSuperviseQuestionModify")
    public R checkFindSuperviseQuestionModify(@RequestParam Map<String, String> params){
        
        SuperviseQuestionModifyEntity srsEntity = new SuperviseQuestionModifyEntity();
        srsEntity = superviseQuestionModifyService.checkFindSuperviseQuestionModify(params);
        return R.ok().put(AttrConstants.DATA, srsEntity);
    }
    
    /**
     * 审核整改
     * 
     * @param params (审核相关信息)
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateCheckSuperviseQuestionModify")
    @Transactional(rollbackFor = Exception.class)
    public R updateCheckSuperviseQuestionModify(@RequestParam Map<String, String> params){
        
        try {
        	long modifyId = Long.valueOf(params.get("modifyId"));
        	SuperviseQuestionModifyEntity sqmEntity = superviseQuestionModifyService.selectById(modifyId);
        	
        	if (sqmEntity != null) {
        		String shzt = sqmEntity.getCheckStatus();
        		if ("0".equals(shzt)) {
        			 boolean  result = superviseQuestionModifyService.updateCheckSuperviseQuestionModify(params);
    	            if (!result) {
    	                return R.error("审核失败！");
    	            }
    	            //insert sys_message
    	            Long srId = Long.valueOf(params.get("dcRecordId"));
    	            SuperviseRecordEntity srEntity = superviseRecordService.selectById(srId);
    	            SysDeptEntity sdEntity = sysDeptService.selectById(srEntity.getToDcdwId());
    	            
    	            String noticeTitle = "整改反馈";
    	    		String contentText = sdEntity.getName() + "单位的整改反馈" + srEntity.getDcry() + "已审核，请查看！";
    	        	
    	        	if (StringUtils.isNotEmpty(noticeTitle)) {
    	            	params.put("noticeTitle", noticeTitle);
    	            }
    	            if (StringUtils.isNotEmpty(contentText)) {
    	            	params.put("noticeContent", contentText);
    	            }
    	        	String deptId = params.get("userDeptId");
    	        	String roles = "";
    	        	if (StringUtils.isNotEmpty(deptId)) {
    	        		roles = commonMethod.getRolesBByDeptId(deptId); //接收角色
    	        	}
    	        	if (StringUtils.isNotEmpty(roles)) {
    	        		params.put("roles", roles);
    	        	}
    	        	sysMessageService.insertMessage(params);
        		} else {
        			R.ok("该整改内容已被其他人审核过，无需再审核！");
        		}
        	}
        	
           
            
        } catch (RRException rre) {
            System.out.println(rre.getMessage());
            return R.error(rre.getMessage());
        }
        
        return R.ok();
    }
    
    /**
     * 整改反馈
     * 
     * @param params (反馈相关信息)
     * @return
     */
    @ResponseBody
    @RequestMapping("/insertFeedBackSuperviseQuestionModify")
    @Transactional(rollbackFor = Exception.class)
    public R insertFeedBackSuperviseQuestionModify(@RequestParam Map<String, String> params){
        try {
            // 督察问题整改记录表
            long sqmId = superviseQuestionModifyService.insertFeedBackSuperviseQuestionModify(params);
            params.put("sqmId", String.valueOf(sqmId));
            // 督察照片表
            superviseImageService.insertSuperviseImage(params);
            
            //update
            String dcQuestionId = params.get("dcQuestionId"); //督察问题id 
            SuperviseQuestionEntity sqEntity = new SuperviseQuestionEntity();
            sqEntity.setId(Long.valueOf(dcQuestionId));
            sqEntity.setModifyStatus("2");
            superviseQuestionService.updateById(sqEntity);

            int countNum = superviseQuestionService.findSuperviseQuestionForModifyStatusNum(params);
            Long srId = Long.valueOf(params.get("dcRecordId"));
            SuperviseRecordEntity srEntity = new SuperviseRecordEntity();
            if (countNum == 0) {
            	srEntity.setId(srId);
            	srEntity.setModifyStatus("2");
            	superviseRecordService.updateById(srEntity);
            }
            // insert sys_message
            srEntity = superviseRecordService.selectById(srId);
            SysDeptEntity sdEntity = sysDeptService.selectById(srEntity.getToDcdwId());
            
            String noticeTitle = "新的整改反馈";
    		String contentText = sdEntity.getName() + "单位有新的整改反馈" + srEntity.getDcry() + "，请审核！";
        	
        	if (StringUtils.isNotEmpty(noticeTitle)) {
            	params.put("noticeTitle", noticeTitle);
            }
            if (StringUtils.isNotEmpty(contentText)) {
            	params.put("noticeContent", contentText);
            }
        	String deptId = params.get("userDeptId");
        	String roles = "";
        	if (StringUtils.isNotEmpty(deptId)) {
        		roles = commonMethod.getRolesBByDeptId(deptId); //接收角色
        	}
        	if (StringUtils.isNotEmpty(roles)) {
        		params.put("roles", roles);
        	}
        	sysMessageService.insertMessage(params);
            
        } catch (RRException rre) {
            System.out.println(rre.getMessage());
            return R.error(rre.getMessage());
        } catch (Exception e) {
            return R.error("反馈失败！");
        }
        
        return R.ok();
    }
    
    /**
     * 查询专项详情的督察模板
     * 
     * @param params 立项的ID
     * @return
     */
    @ResponseBody
    @RequestMapping("/findSuperviseTempletList")
    public R findSuperviseTempletList(@RequestParam Map<String, String> params){
        
        int countNum = 0;
        countNum = superviseTempletService.findSuperviseTempletListCount(params);
        List<SuperviseTempletEntity> stsList =  new ArrayList<SuperviseTempletEntity>();
        if (countNum != 0) {
            stsList = superviseTempletService.findSuperviseTempletList(params);
        }
        
        return R.ok().put(AttrConstants.DATA, stsList).put(AttrConstants.COUNT_NUM, countNum);
    }


    /**
     *分类督查查询小项
     * @param deptId  部门Id
     * @param userId  用户Id
     * @param categoryNumber  类别：1队伍管理；2执法执勤；3社会管控；4其他督查,5每日必查
     * @return
     */
    @ResponseBody
    @RequestMapping("/getStandardProblemSmall")
    public R getStandardProblemSmall(String deptId,String userId,String categoryNumber,String name){
        if(StringUtil.isEmpty(deptId) || StringUtil.isEmpty(userId) || StringUtil.isEmpty(categoryNumber)){
            return R.error("3","参数有缺失") ;
        }
        SysDeptEntity dept = sysDeptDao.selectById(deptId);
        String sfdctx = dept.getSfdctx();
        if("1".equals(sfdctx)){
            deptId = dept.getParentId() + "";
        }
        String qhId = dept.getQhId() + "";
        //获取对应标准模板ID
        Long templetId = superviseTempletConfDao.queryTempletIdByRQ(userId,deptId,qhId,categoryNumber);
        if(templetId == null){
            if("5".equals(categoryNumber)){
                return R.error("2","没有每日必查模板请新建！");
            }
            templetId = Long.parseLong(categoryNumber);
        }
        //查询对应小类
        List<Map<String,Object>> list = superviseStandardDao.queryTempletSmall(templetId,name);
        return R.ok().put("data",list).put("templetId",templetId);
    }

    /**
     * 分类督查查询检查项
     * @param code  多个code 用逗号分隔，全部检查项 code不传
     * @param templetId
     * @return
     */
    @ResponseBody
    @RequestMapping("/getCheckList")
    public R getCheckList(String code,String templetId){
        if(StringUtil.isEmpty(templetId)){
            return R.error("3","参数有缺失") ;
        }
        //查询检查项
        List<Map<String,Object>> list = superviseStandardDao.queryCheckListByEjCode(templetId, code, 3);
        for (Map<String,Object> m : list) {
            m.put("checkList",superviseStandardDao.queryCheckListByEjCode(templetId,m.get("sbdm").toString(),4));
        }
        return R.ok().put("data",list);
    }
    
    /**
     * 检查是否督察过
     * 
     * @param params (专项ID, 用户单位ID)
     * @return
     */
    @ResponseBody
    @RequestMapping("/checkSuperviseRecordCount")
    public R checkSuperviseRecordCount(@RequestParam Map<String, String> params){
        
        int countNum = superviseRecordService.checkSuperviseRecordCount(params);
        
        return R.ok().put(AttrConstants.COUNT_NUM, countNum);
    }

    /**
     *常用检查项
     * @param userId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getCommonCheck")
    public R getCommonCheck(String userId, int currPage, int pageSize) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("userId",userId);
        int count = superviseStandardDao.getCommonCheck(map).size();
        map.put("currPage",(currPage-1)*pageSize);
        map.put("pageSize",pageSize);
        List<Map<String,Object>> list = superviseStandardDao.getCommonCheck(map);
        return R.ok().put(AttrConstants.DATA,list).put("count",count);
    }

    /**
     * 修改部门表被管辖单位Id
     */
    @ResponseBody
    //@RequestMapping(value = "editQhId")
    public R editQhId() {
       List<SysDeptFormMap> list = sysDeptDao.getAllDcdw();

        for (SysDeptFormMap s : list) {
            sysDeptDao.editQhIdByRangeCode(s.getLong("d"),s.getStr("c"));
        }
        return R.ok();
    }

    @ResponseBody
    //@RequestMapping(value = "addUser")
    public R addUser() {
        List<SysDeptFormMap> list = sysDeptDao.getAlldcuser();

        for (SysDeptFormMap s : list) {

            String xms = s.getStr("dwmj");
            String[] xmss = xms.split("、");
            for (int i = 0; i < xmss.length; i++) {
                SysUserEntity user = new SysUserEntity();
                user.setUserFlag("2");//非系统用户
                user.setName(xmss[i]);//姓名
                user.setDeptId(s.getLong("deptid"));//部门id
                user.setCreateTime(new Date());
                user.setCreateUser(1L);
                user.setUpdateTime(new Date());
                user.setUpdateUser(1L);
                sysUserService.save(user);
            }

            /*user.setDeptId(Long.parseLong(s.getStr("deptid")));//单位
            user.setUsername(s.get("jh").toString());//账号
            user.setPassword("123456");//密码
            user.setStatus(1);//是否激活
            user.setName(s.getStr("xm"));//姓名
            user.setPoliceId(s.get("jh").toString());//警号
            user.setCreateTime(new Date());
            user.setCreateUser(1L);
            user.setUpdateTime(new Date());
            user.setUpdateUser(1L);
            List<Long> roleList = new ArrayList<Long>();
            roleList.add(Long.parseLong(s.getStr("roleid")));
            user.setRoleIdList(roleList);
            sysUserService.save(user);*/

        }
        return R.ok();
    }



}
